package com.shopping.dev.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;

@Aspect
@Component

public class ServiceLogAspect {
    public static final Logger LOGGER = LoggerFactory.getLogger(ServiceLogAspect.class);
    @Around("execution(* com.shopping.dev.service.impl..*.*(..))")

    public Object recordLog(ProceedingJoinPoint joinPoint) throws Throwable {
        LOGGER.info("===== 开始执行 =====");

        LOGGER.info("执行的类：{}",joinPoint.getTarget().getClass());
        LOGGER.info("执签名：{}",joinPoint.getSignature().getName());
        long begintime = System.currentTimeMillis();
        Object proceed = joinPoint.proceed();
        long endtime = System.currentTimeMillis();
        long taketime = endtime - begintime;
        if (taketime>3500){
            LOGGER.error("===== 执行完毕，耗时：{} =====", taketime);
        }else{
            LOGGER.info("===== 执行完毕，耗时：{} =====", taketime);
        }
        return proceed;

    }
}
